<template>
	<view>
		<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">创客中心</block>
		</cu-custom>
		<!-- 背景图 -->
		<image class="backImage" src="https://app.yycjkb.cn/index/fujiajia/111.png" mode="widthFix"></image>

		<view class="container">
			<!-- 用户信息 -->
			<view class="user-info">
				<view class="user-info-left">
					<image v-if="userInfo.luohan==1" class="user-info-image" src="/static/luohan.png" mode="aspectFill">
					</image>
					<image v-else class="user-info-image" :src="userInfo.avatar || '/static/default_avatar.png'"
						mode=""></image>
					<view class="user-info-name">
						<view class="name">{{ userInfo.nickname }}</view>
						<view class="info">
							<view class="uid">UID: {{ userInfo.id }}</view>
							<view class="contribute">贡献值: {{ userInfo.contribution }}</view>
						</view>
					</view>
				</view>
				<view class="user-info-right">
					<image class="medal" :src="userInfo.user_fee_level" mode=""></image>
					<!-- <view class="post">
						<image class="gradient" src="https://app.yycjkb.cn/index/fujiajia/jianbian.png" mode="">
						</image>
						<view>{{ userInfo.user_level > 1 ? '拓店者' : '业务员' }}</view>
					</view> -->
				</view>
			</view>

			<!-- 钱包 -->
			<view class="money-bag">
				<image class="money-bag-image" src="https://app.yycjkb.cn/index/fujiajia/jianbianback.png" mode="">
				</image>
				<view class="money-bag-content">
					<view class="money-content-left">
						<view class="">
							<image src="#" mode=""></image>
							<text class="shopTitle">拓店者管理中心</text>
						</view>
						<view class="">
							<image src="#" mode=""></image>
							解锁所有权限
						</view>
					</view>
				</view>
			</view>

			<!-- 小助手 -->
			<view class="small-assistant">
				<view class="assistant-content">
					<view class="assistant-item" @tap="navigateTo(item.url)" v-for="item in assistant"
						:key="item.title">
						<view class="assistant-image-box">
							<image :src="item.image_url" mode=""></image>
						</view>
						<view class="assistant-item-title">
							{{ item.title }}
						</view>
					</view>
					<view class="assistant-item" @click="hideModal">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/141.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							结算卡认证
						</view>
					</view>
				</view>


				<!-- 返回按钮 -->
				<view class="back-button" @click="goBack">
					返回
				</view>
			</view>
		</view>
		<view class="cu-modal" style="z-index: 99;" :class="modalActive ? 'show' : ''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">提示</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-sm">
					<view class="moda-msg">{{message}}</view>
					<radio-group @change="radioChange">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
							<view class="uni-list-cell-item">
								<radio :value="item.value" :checked="index === current" />
								<text>{{item.name}}</text>
							</view>
						</label>
					</radio-group>
				</view>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub text-green solid-left" @tap="hideModal">取消</view>
					<view class="action margin-0 flex-sub  solid-left" @tap="selectWay">确定</view>
				</view>
			</view>
		</view>

		<!-- 底部tabbar -->
		<!-- <tabBar :selectIndex="selectIndex"></tabBar> -->
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import shop from '@/api/shop';
	import tabBar from "../../components/tabBar/index.vue";

	export default {
		components: {
			tabBar
		},
		data() {
			return {
				form: {
					title: '',
					bind_uid: '',
					logo: '',
					agent_uid: '',
					discount: '',
					reason: '',
					region: ['北京市', '北京市', '东城区'],
					indoor_pic: '',
					address: '',
					lng: '',
					lat: '',
					albumInfo: '',
					mobile: '',
					type: '',
					position: 'boss'
				},
				signUp: 'https://f.hhs8888.com/pay/index/signUp',
				modalActive: false,
				title: '',
				current: '',
				imgList: [],
				loading: false,
				items: [{
					name: '自动审核通道(推荐)',
					value: 1
				}, {
					name: '人工审核通道',
					value: 0
				}],
				selectIndex: 2,
				assistant: [{
						image_url: 'https://app.yycjkb.cn/index/fujiajia/12.png',
						title: '我的商家',
						url: '/pages/my/agent/shop'
					},
					{
						image_url: 'https://app.yycjkb.cn/index/fujiajia/17.png',
						title: '我的收益',
						url: '/pages/my/agent/rebate'
					},
					{
						image_url: 'https://app.yycjkb.cn/index/fujiajia/13.png',
						title: '拓店申请',
						url: '/pages/my/agent/shopApply'
					}
				]
			};
		},
		computed: {
			...mapState(['config', 'hasLogin', 'userInfo']) // 从 Vuex 获取用户信息
		},
		methods: {
			radioChange(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value == evt.target.value) {
						this.current = i;
						break;
					}
				}
			},
			selectWay() {
				const that = this;
				this.form.type = this.items[this.current].value;
				// 处理albumInfo字段 多个完整的URL地址以英文逗号,隔开
				this.form.albumInfo = this.imgList.join(",");
				shop.apply(this.form).then(res => {
					this.hideModal()
					if (res.data) {
						this.jumpTo(res.data.url, 'web')
					} else if (res.code == 0) {
						this.toast(res.msg);
					}
				})
			},
			async hideModal() {
				this.modalActive = !this.modalActive;
			},
			goBack() {
				uni.navigateBack();
			},
			navigateTo(routeName) {
				uni.navigateTo({
					url: routeName
				})
				// 根据routeName跳转到相应的页面
				console.log(`Navigating to ${routeName}`);
			},
		}
	};
</script>



<style lang="less" scoped>
	.backImage {
		width: 100%;
		position: absolute;
		left: 0%;
	}

	.container {
		padding-top: 140rpx;
		padding-bottom: 178rpx;
		width: 690rpx;
		margin: auto;
		position: relative;

		.user-info {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.user-info-left {
				display: flex;

				.user-info-image {
					width: 137rpx;
					height: 137rpx;
					border-radius: 100rpx;
				}

				.user-info-name {
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					padding: 10rpx 20rpx;

					.info {
						color: #666666;
						font-size: 24rpx;
						line-height: 140%;
					}
				}
			}

			.user-info-right {
				text-align: center;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.medal {
					width: 150rpx;
					height: 146rpx;
					margin-bottom: -5rpx;
				}

				.post {
					width: 98rpx;
					height: 38rpx;
					position: relative;
					color: #fff;
					padding: 10rpx 0;

					.gradient {
						width: 100%;
						height: 100%;
						position: absolute;
						left: 50%;
						transform: translate(-50%, 0);
					}

					view {
						z-index: 16;
						position: relative;
						line-height: 38rpx;
						transform: scale(0.8) !important;
						font-size: 16rpx;
					}
				}
			}
		}

		.money-bag {
			padding-top: 30rpx;

			.shopTitle {
				font-size: 30rpx;
				font-weight: bold;
			}

			.money-bag-image {
				width: 100%;
				height: 126rpx;
				position: absolute;
			}

			.money-bag-content {
				position: relative;
				padding: 0 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 126rpx;

				.money-content-left {
					color: #FFF;

					view {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						padding: 4rpx 0;

						image {
							vertical-align: middle;
							margin-right: 10rpx;
							width: 34rpx;
							height: 34rpx;
						}
					}
				}
			}
		}

		.small-assistant {
			width: 100%;
			background-color: #fff;
			border-radius: 24rpx;
			margin-top: 30rpx;
			padding: 20rpx 30rpx;

			.assistant-content {
				padding-top: 40rpx;
				display: grid;
				grid-template-columns: repeat(4, 1fr);
				gap: 10px;
				place-items: center;
				width: 100%;

				.assistant-item {
					width: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					text-align: center;
					margin-bottom: 20rpx;

					image {
						width: 58rpx;
						height: 58rpx;
					}

					.assistant-item-title {
						font-size: 24rpx;
						padding-top: 6rpx;
					}
				}
			}

			.back-button {
				width: 230rpx;
				height: 76rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin: 40rpx auto;
				margin-top: 100rpx;
				background: linear-gradient(90deg, rgba(254, 176, 122, 1) 35%, rgba(242, 171, 235, 1) 100%);
				border-radius: 20rpx;
				color: #fff;
			}
		}
	}
</style>